package com.obtk.property.controller;


import com.github.pagehelper.Page;
import com.obtk.property.common.MessageOwner;
import com.obtk.property.common.PageResult;
import com.obtk.property.common.Result;
import com.obtk.property.common.StatusCode;
import com.obtk.property.pojo.Owner;
import com.obtk.property.service.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/owner")
public class OwnerController {

    @Autowired
    private OwnerService ownerService;

    @RequestMapping("/find")
    public Result find(){
      List<Owner> all=ownerService.findAll();
      return new Result(true,200,"请求成功",all);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        System.out.println(searchMap);
        Page<Owner> page = ownerService.search(searchMap);
        return new PageResult(true, StatusCode.OK, MessageOwner.Owner_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Owner owner){
        Boolean add = ownerService.add(owner);
        return new Result(true,StatusCode.OK, MessageOwner.Owner_ADD_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(Integer ownerId){
        Owner owner = ownerService.findById(ownerId);
        return new Result(true,StatusCode.OK, MessageOwner.Owner_FIND_BY_ID_SUCCESS,owner);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Owner owner){
        Boolean add = ownerService.update(owner);
        return new Result(true,StatusCode.OK, MessageOwner.Owner_UPDATE_SUCCESS);
    }
    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean flag = ownerService.del(ids);
        return new Result(true,StatusCode.OK, MessageOwner.Owner_DELETE_SUCCESS);
    }
}
